﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CC;

namespace RFMS
{
    public partial class Hoofdscherm : Form
    {
        public Hoofdscherm(string gebruikersnaam, string functie)
        {
            InitializeComponent();
            this._gebruikersnaam = gebruikersnaam;
            this._functie = functie;
            //FormBorderStyle = FormBorderStyle.None;
            //WindowState = FormWindowState.Maximized;
            //TopMost = true;
        }

        private TafelBeheer _tafelBeheer;
        private string _gebruikersnaam;
        private string _functie;

        private void Hoofdscherm_Load(object sender, EventArgs e)
        {
            LaadTafels();
            TekenBar();
            buttonUitloggen.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 94, 10);
        }

        private void LaadTafels()
        {
            foreach (Control c in this.Controls)
            {
                if (c is PictureBox)
                {
                    this.Controls.Remove(c);
                }
            }

            _tafelBeheer = new TafelBeheer();
            List<List<string>> lijst = _tafelBeheer.LijstVanTafels();
            PictureBox pictureBox;

            foreach (List<string> s in lijst)
            {
                Point point = new Point(Convert.ToInt32(s[2]), Convert.ToInt32(s[3]));
                pictureBox = new PictureBox();
                pictureBox.Location = point;
                pictureBox.Name = s[1];
                pictureBox.Cursor = Cursors.Hand;
                pictureBox.MouseDown += new MouseEventHandler(pictureBox_MouseDown);
                pictureBox.Width = 95;
                pictureBox.Height = 100;
               // pictureBox.Location = new Point(Convert.ToInt32(s[2]), Convert.ToInt32(s[3]));
                pictureBox.Image = Image.FromFile("stoeltafel1.png");
                pictureBox.BackColor = Color.Transparent;
                this.Controls.Add(pictureBox);
                Label label = new Label();
                label.ForeColor = Color.Black;
                label.BackColor = Color.Transparent;
                label.Location = new Point(point.X, point.Y + 100);
                label.Text = s[1];
                this.Controls.Add(label);
            }
        }

        private void TekenBar()
        {
            var bar = new PictureBox
                          {
                              Location = new Point(Screen.PrimaryScreen.Bounds.Width - 200, 200),
                              Image = Image.FromFile("bar.png"),
                              BackColor = Color.Transparent,
                              Height = 500,
                              Width = 200
                          };
            Controls.Add(bar);
        }

        void pictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            var opnemen = new BestellingOpnemen(this._gebruikersnaam, (sender as PictureBox).Name, _functie);
            opnemen.ShowDialog();
        }

        private void buttonUitloggen_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Hoofdscherm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Close();
            }

            if (e.KeyCode == Keys.F5)
            {
                LaadTafels();
            }
        }
    }
}
